<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="组织机构代码证号" label-width="125px" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          placeholder="请输入组织机构代码证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['qyxy:score:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['qyxy:score:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['qyxy:score:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['qyxy:score:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="scoreList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="组织机构代码证号"
        align="center"
        prop="borgCode"
      />
      <el-table-column label="企业名称" align="center" prop="orgName" />
      <el-table-column label="最终得分" align="center" prop="finalScore" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-notebook-2"
            @click="handleUpdate(scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业得分对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
      :before-close="cancel"
    >
      <h1>企业总得分 : {{ detail.sumScore }}</h1>
      <h3>资质类别得分 : {{ detail.typeScore }}</h3>
      <h4><b>得分资质:</b></h4>
      <el-table :data="typeInfo" style="width: 100%">
        <el-table-column prop="quaName" label="资质名称" width="180">
        </el-table-column>
        <el-table-column prop="quaType" label="资质类别" width="180">
        </el-table-column>
        <el-table-column prop="quaRank" label="资质等级"> </el-table-column>
      </el-table>
      <h3>资质人员得分 : {{ detail.personScore }}</h3>
      <el-table :data="detail.personDetailList" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <!-- {{ props.row.name }} -->
            <template v-if="props.row.addScore">
              <b>加分 : {{ props.row.addScore }}</b><br/>
              <b
                >加分注册人员:
                {{ JSON.parse(props.row.addScorePerson).length }}人</b
              >
              <el-table
                :data="JSON.parse(props.row.addScorePerson)"
                style="width: 100%"
              >
                <el-table-column label="姓名" prop="pname"> </el-table-column>
                <el-table-column label="身份证" prop="idNum"> </el-table-column>
                <el-table-column label="人员类别" prop="regType">
                </el-table-column>
                <el-table-column label="专业类别" prop="regSpty">
                </el-table-column>
              </el-table>
              <hr />
              <hr />
            </template>
            <template v-if="props.row.reduceScore">
              <b>减分 : {{ props.row.reduceScore }}</b>
              <hr />
            </template>
            <b
              >资质使用注册人员:
              {{ JSON.parse(props.row.useZzPerson).length }}人</b
            >
            <el-table
              :data="JSON.parse(props.row.useZzPerson)"
              style="width: 100%"
            >
              <el-table-column label="姓名" prop="pname"> </el-table-column>
              <el-table-column label="身份证" prop="idNum"> </el-table-column>
              <el-table-column label="人员类别" prop="regType">
              </el-table-column>
              <el-table-column label="专业类别" prop="regSpty">
              </el-table-column>
            </el-table>
            <hr />
            <b>资质缺少注册人员 : {{ props.row.shortOfZz }} 人</b>
            <hr />
            <b
              >资质使用职称人员 :
              {{ JSON.parse(props.row.useZcPerson).length }}人</b
            >
            <el-table
              :data="JSON.parse(props.row.useZcPerson)"
              style="width: 100%"
            >
              <el-table-column label="姓名" prop="pname"> </el-table-column>
              <el-table-column label="身份证" prop="idNum"> </el-table-column>
              <el-table-column label="职称类别" prop="certSpty">
              </el-table-column>
              <el-table-column label="级别" prop="certRank"> </el-table-column>
            </el-table>
            <hr />
            <b>资质缺少职称人员 : {{ props.row.shortOfZc }} 人</b>
            <hr />
            <b
              >资质缺少职称类别:
              <template v-for="s in JSON.parse(props.row.shortOfZcType)">
                {{ s }}、
              </template>
            </b>
            <hr />
          </template>
        </el-table-column>
        <el-table-column label="资质名称" prop="quaName"> </el-table-column>
        <el-table-column label="资质类别" prop="quaType"> </el-table-column>
        <el-table-column label="等级" prop="quaRunk"> </el-table-column>
        <el-table-column label="是否符合标准" prop="isConformTo">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listScore,
  getScore,
  delScore,
  addScore,
  updateScore,
  exportScore,
} from "@/api/qyxy/score";

export default {
  name: "Score",
  components: {},
  data() {
    return {
      typeInfo: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业得分表格数据
      scoreList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgCode: null,
        orgName: null,
        finalScore: null,
      },
      detail: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业得分列表 */
    getList() {
      this.loading = true;
      listScore(this.queryParams).then((response) => {
        this.scoreList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.typeInfo = [];
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orgCode: null,
        orgName: null,
        finalScore: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业得分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orgCode = row.orgCode;
      const borgCode = row.borgCode;
      const orgName = row.orgName;
      getScore(orgCode).then((response) => {
        this.detail = response.data;
        this.open = true;
        this.title = orgName + "[" + borgCode + "]" + "得分明细";
        //资质类别得分集合处理
        if (this.typeInfo.length == 0) {
          this.typeInfo.push(this.detail.typeDetail);
        }
        console.log(this.detail);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateScore(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScore(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除企业得分编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delScore(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有企业得分数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportScore(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
